package hotel.switchs.oversea.online.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.entity.SwitchsPoolOrderStateHistory;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.meituan.MtHotelOrderJobDealVo;
import hotel.switchs.oversea.api.VO.order.OperateDltOrder;
import hotel.switchs.oversea.api.VO.order.OrderListSearchVO;
import hotel.switchs.oversea.api.VO.order.OrderListVO;
import hotel.switchs.oversea.api.dto.SwitchCreateRoomDto;
import hotel.switchs.oversea.api.entity.order.SwitchOrderInfo;
import hotel.switchs.oversea.api.entity.order.SwitchOrderListNotify;
import hotel.switchs.oversea.api.entity.order.SwitchOrderPool;
import hotel.switchs.oversea.online.mapper.SwitchOrderInfoMapper;
import hotel.switchs.oversea.online.mapper.SwitchOrderListNotifyMapper;
import hotel.switchs.oversea.online.mapper.SwitchOrderPoolMapper;
import hotel.switchs.oversea.online.mapper.SwitchsPoolOrderStateHistoryMapper;
import hotel.switchs.oversea.online.service.SwitchCreateRoomService;
import hotel.switchs.oversea.online.service.SwitchOrderInfoService;
import hotel.switchs.oversea.online.service.SwitchOrderPoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description: 携程订单池pool
 * @Author: Qiu·yy
 * @date: 2020/7/9
 */
@Slf4j
@Service
public class SwitchOrderPoolServiceImpl extends BaseServiceImpl<SwitchOrderPool> implements SwitchOrderPoolService {

    @Value("${profile.type}")
    private String profile;

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private SwitchOrderPoolMapper switchOrderPoolMapper;

    @Autowired
    private SwitchOrderInfoMapper switchOrderInfoMapper;

    @Autowired
    private SwitchOrderInfoService switchOrderInfoService;

    @Autowired
    private SwitchsPoolOrderStateHistoryMapper switchsPoolOrderStateHistoryMapper;

    @Autowired
    private SwitchOrderListNotifyMapper switchOrderListNotifyMapper;

    @Autowired
    private SwitchCreateRoomService switchCreateRoomService;


    @Override
    public Result<Object> updatePoolIsOrderByMdkey(List<String> md5KeyList) {
        Map map = new HashMap();
        map.put("md5KeyList",md5KeyList);
        switchOrderPoolMapper.updatePoolIsOrderByMdkey(map);
        return new Result<>();
    }

    @Override
    public List<SwitchOrderPool> getSwitchOrderInfoForMtAsc() {
        return switchOrderPoolMapper.getSwitchOrderInfoForMtAsc();
    }

    @Override
    public Integer hasMtBooking(String orderId) {
        return switchOrderPoolMapper.hasMtBookingBySwOrderId(orderId);
    }

    @Override
    public Integer checkExistValiBookingBySwOrderId(String orderId) {
        return switchOrderPoolMapper.checkExistValiBookingBySwOrderId(orderId);
    }

    @Override
    public void updateOrderResult(SwitchOrderPool switchOrderPool) {
        switchOrderPoolMapper.updateOrderResult(switchOrderPool);
        String desc = switchOrderPool.getRemark();
        if(ObjectUtils.isEmpty(switchOrderPool.getRemark())){
            desc = switchOrderPool.getIsOrderRemark();
        }
        this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),switchOrderPool.getMtOrderState(),switchOrderPool.getIsOrder(),desc);
    }
    @Override
    public void updateOrderResultNotSaveLog(SwitchOrderPool switchOrderPool) {
        switchOrderPoolMapper.updateOrderResult(switchOrderPool);
    }

    public void insertPoolStateHistroy(String orderId,Integer sysState,String mtState,Integer isOrder,String remark){
        SwitchsPoolOrderStateHistory switchsPoolOrderStateHistory = new SwitchsPoolOrderStateHistory();
        switchsPoolOrderStateHistory.setId(StringUtil.getUUID());
        switchsPoolOrderStateHistory.setOrderId(orderId);
        switchsPoolOrderStateHistory.setCreateTime(new Date());
        switchsPoolOrderStateHistory.setIsOrder(isOrder);
        switchsPoolOrderStateHistory.setSysStatus(sysState);
        switchsPoolOrderStateHistory.setMtStatus(mtState==null?null:Integer.valueOf(mtState));
        switchsPoolOrderStateHistory.setRemark(remark);
        try{
            switchsPoolOrderStateHistoryMapper.insert(switchsPoolOrderStateHistory);
        }catch (Exception e){
            log.error("switchsPoolOrderStateHistoryMapper 保存异常："+e.getMessage());
            e.printStackTrace();
        }
    }

    @Override
    public Result<Object> getDelayChangeBookingOrders() {
        List<SwitchOrderPool> ids = switchOrderPoolMapper.getDelayChangeBookingOrders();
        if(null != ids && ids.size()>0){
            return new Result<>(JSON.toJSONString(ids),"success");
        }
        return new Result<>();
    }

    @Override
    public Result<Object> getDelayRejectBookingOrders(){
        //version 20200907  qyy 查询所有延迟单
        List<String> ids = switchOrderPoolMapper.getDelayRejectBookingOrders(null);//返回md5key
        if(null == ids || ids.size()==0 || null == ids.get(0)){
            return new Result<>(new ArrayList<>());
        }
        List<String> idsNeed = new ArrayList<>();
        for(String id:ids){
            //version 20200828 判断是否延迟单超过2小时，则改为12  不处理等待携程操作发送通知单    系统状态12  美团状态 0  延迟改为1 立即下单
            Example example = new Example(SwitchOrderListNotify.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("md5Key",id);
            SwitchOrderListNotify switchOrderListNotify = switchOrderListNotifyMapper.selectOneByExample(example);
            String orderId = switchOrderListNotify.getOrderId();//订单id

            SwitchOrderPool switchOrderPool = switchOrderPoolMapper.findOrderBySwitchOrderId(orderId);
            Integer waitMin = switchOrderPool.getOrderWaitTime();
            Date waitDate = DateUtil.addSecond(switchOrderPool.getCreateTime(),waitMin*60);
            Long min = DateUtil.dateDiff(DateUtil.getCurrTime(),"min",DateUtil.formatDate(waitDate,"yyyy-MM-dd HH:mm:ss"),"yyyy-MM-dd HH:mm:ss");
            if(min<=0){
                //延时单超过120小时，将改为人工单，定时器不再操作
                switchOrderPool.setIsOrder(1);
                switchOrderPool.setSysOrderState(12);
                switchOrderPool.setMtOrderState("0");
                switchOrderPool.setRemark(DateUtil.getCurrTime()+" 延时单超过40分钟，将改为人工单，定时器不再操作");
                updateOrderResult(switchOrderPool);
                this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),switchOrderPool.getMtOrderState(),switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
                //return new Result<>("超时单", CommonConstants.REQUEST_ERROR);
            }else{
                idsNeed.add(id);
            }
        }
        return new Result<>(idsNeed);
    }

    public static void main(String[] args) {
        Integer waitMin = 120;
        Date waitDate = DateUtil.addSecond("2020-09-18 12:55:00",waitMin*60);
        System.out.printf("=========="+DateUtil.formatDate(waitDate,"yyyy-MM-dd HH:mm:ss"));
        Long min = DateUtil.dateDiff(DateUtil.getCurrTime(),"min",DateUtil.formatDate(waitDate,"yyyy-MM-dd HH:mm:ss"),"yyyy-MM-dd H:mm:ss");
        if(min<=0){
            System.out.printf("=========="+min);
        }

    }

    @Override
    public Result<Object> getOrderList(OrderListSearchVO orderListSearchVO) {
        PageHelper.startPage(orderListSearchVO.getPageCode(),orderListSearchVO.getPageSize());
        List<OrderListVO> orderPoolList = switchOrderPoolMapper.getOrderList(orderListSearchVO);
        for (OrderListVO orderListVO : orderPoolList) {
            orderListVO.setOrderDate(DateUtil.switchTimeParse(orderListVO.getOrderDate()));
            orderListVO.setCheckinDate(DateUtil.switchDateParse(orderListVO.getCheckinDate()));
            orderListVO.setCheckoutDate(DateUtil.switchDateParse(orderListVO.getCheckoutDate()));
        }
        PageInfo<OrderListVO> pageInfo = new PageInfo<>(orderPoolList);
        return new Result<>(pageInfo);
    }

    /**
     * <H1>人工采购</H1>
     *当系统状态=2 + 美团状态=0未下单 + 订单下单=0非立即下单    可操作人工采购
     * @return hotel.base.oversea.utils.Result<java.lang.Object>
     * @author HuangT
     * @Date 2020/9/7 15:01
     */
    @Override
    public Result<Object> updateOrderStateAboutRgxd(SwitchOrderPool pool) {
        //人工向美团下单
        pool.setSysOrderState(40);
        pool.setIsOrder(1);
        pool.setRemark(DateUtil.getCurrTime() + " 当前为后台系统人工下单操作!");
        switchOrderPoolMapper.updateOrderState(pool);
        this.insertPoolStateHistroy(pool.getOrderId(),pool.getSysOrderState(),
                null,pool.getIsOrder(),pool.getRemark());

        //调用美团下单接口

        String orderId = pool.getOrderId();
        Example example = new Example(SwitchOrderPool.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("orderId",orderId);
        SwitchOrderPool switchOrderPool = switchOrderPoolMapper.selectOneByExample(example);
        Map switchOrderInfoMap = new HashMap();
        switchOrderInfoMap.put("orderId",orderId);
        SwitchOrderInfo switchOrderInfo = switchOrderInfoMapper.findOneByOrderId(switchOrderInfoMap);

        MtHotelOrderJobDealVo mtHotelOrderJobDealVo = new MtHotelOrderJobDealVo();
        mtHotelOrderJobDealVo.setSwPoolId(switchOrderPool.getId());
        mtHotelOrderJobDealVo.setSwOrderId(switchOrderPool.getOrderId());
        mtHotelOrderJobDealVo.setSwHotelId(switchOrderInfo.getHotelId());
        mtHotelOrderJobDealVo.setSwRoomId(switchOrderInfo.getRoomId());
        mtHotelOrderJobDealVo.setCheckinDate(DateUtil.switchDateParse(switchOrderInfo.getCheckinDate()));
        mtHotelOrderJobDealVo.setCheckoutDate(DateUtil.switchDateParse(switchOrderInfo.getCheckoutDate()));
        mtHotelOrderJobDealVo.setRoomnum(switchOrderInfo.getRoomnum());
        mtHotelOrderJobDealVo.setTotalPrice(switchOrderInfo.getOrderPrice().multiply(new BigDecimal(100)).intValue());
        mtHotelOrderJobDealVo.setPersonNames(switchOrderInfo.getCustomerName());
        mtHotelOrderJobDealVo.setContactName(switchOrderInfo.getContactName());
        mtHotelOrderJobDealVo.setContactPhone("4009700950");
        mtHotelOrderJobDealVo.setSysStatus(40);//40 人工采购
        //获取美团对应酒店id 商品id
        SwitchCreateRoomDto switchCreateRoomDto = switchCreateRoomService.getMtInfoBySwitchRoomId(Integer.valueOf(switchOrderInfo.getRoomId()));
        log.info("人工采购switchCreateRoomDto={}",switchCreateRoomDto);
        mtHotelOrderJobDealVo.setMtHotelId(String.valueOf(switchCreateRoomDto.getMtHotelId()));
        mtHotelOrderJobDealVo.setGoodsId(switchCreateRoomDto.getMtGoodId());
        String dataJson = JacksonUtil.objectToJson(mtHotelOrderJobDealVo);
        log.info("人工采购dataJson={}",dataJson);
        //调用美团下单接口
        SendUtils.dingMsgOrder("[HHB-RG-BOOKING] 很好办后台人工采购 ",DateUtil.getCurrTime()+" 订单号="+switchOrderPool.getOrderId(), MessageEnums.genre.ORDER_NOTICY.getCode(),switchOrderPool.getOrderId(),restTemplate);
        Result bookingResult = RestTemplateUtils.post(CommonUrlConstants.MEITUAN_HOST+"/mtHotelOrderDeal/jobNewOrderBooking",dataJson,restTemplate);
        if(bookingResult.getCode()==CommonConstants.SUCCESS){
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购成功!", CommonConstants.SUCCESS);
        }else{
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购失败!"+ JSON.toJSONString(bookingResult), CommonConstants.REQUEST_ERROR);
        }

    }


    @Override
    public Result<Object> updateOrderStateAboutLossBefore(SwitchOrderPool pool) {
        //亏损单1直采（拆单前的订单价格）
        pool.setSysOrderState(40);
        pool.setIsOrder(1);
        pool.setRemark(DateUtil.getCurrTime() + " 当前为后台系统人工下单操作!");
        switchOrderPoolMapper.updateOrderState(pool);
        this.insertPoolStateHistroy(pool.getOrderId(),pool.getSysOrderState(),
                null,pool.getIsOrder(),pool.getRemark());

        //调用美团下单接口

        String orderId = pool.getOrderId();
        Example example = new Example(SwitchOrderPool.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("orderId",orderId);
        SwitchOrderPool switchOrderPool = switchOrderPoolMapper.selectOneByExample(example);
        Map switchOrderInfoMap = new HashMap();
        switchOrderInfoMap.put("orderId",orderId);
        SwitchOrderInfo switchOrderInfo = switchOrderInfoMapper.findOneByOrderId(switchOrderInfoMap);

        MtHotelOrderJobDealVo mtHotelOrderJobDealVo = new MtHotelOrderJobDealVo();
        mtHotelOrderJobDealVo.setSwPoolId(switchOrderPool.getId());
        mtHotelOrderJobDealVo.setSwOrderId(switchOrderPool.getOrderId());
        mtHotelOrderJobDealVo.setSwHotelId(switchOrderInfo.getHotelId());
        mtHotelOrderJobDealVo.setSwRoomId(switchOrderInfo.getRoomId());
        mtHotelOrderJobDealVo.setCheckinDate(DateUtil.switchDateParse(switchOrderInfo.getCheckinDate()));
        mtHotelOrderJobDealVo.setCheckoutDate(DateUtil.switchDateParse(switchOrderInfo.getCheckoutDate()));
        mtHotelOrderJobDealVo.setRoomnum(switchOrderInfo.getRoomnum());
        mtHotelOrderJobDealVo.setTotalPrice(switchOrderInfo.getOrderPrice().multiply(new BigDecimal(100)).intValue());
        mtHotelOrderJobDealVo.setPersonNames(switchOrderInfo.getCustomerName());
        mtHotelOrderJobDealVo.setContactName(switchOrderInfo.getContactName());
        mtHotelOrderJobDealVo.setContactPhone("4009700950");
        mtHotelOrderJobDealVo.setSysStatus(40);//40 人工采购
        //获取美团对应酒店id 商品id
        SwitchCreateRoomDto switchCreateRoomDto = switchCreateRoomService.getMtInfoBySwitchRoomId(Integer.valueOf(switchOrderInfo.getRoomId()));
        log.info("人工采购switchCreateRoomDto={}",switchCreateRoomDto);
        mtHotelOrderJobDealVo.setMtHotelId(String.valueOf(switchCreateRoomDto.getMtHotelId()));
        mtHotelOrderJobDealVo.setGoodsId(switchCreateRoomDto.getMtGoodId());
        String dataJson = JacksonUtil.objectToJson(mtHotelOrderJobDealVo);
        log.info("人工采购dataJson={}",dataJson);
        //调用美团下单接口
        SendUtils.dingMsgOrder("[HHB-RG-BOOKING] 很好办后台人工采购 ",DateUtil.getCurrTime()+" 订单号="+switchOrderPool.getOrderId(), MessageEnums.genre.ORDER_NOTICY.getCode(),switchOrderPool.getOrderId(),restTemplate);
        Result bookingResult = RestTemplateUtils.post(CommonUrlConstants.MEITUAN_HOST+"/mtHotelOrderDeal/jobNewOrderBooking",dataJson,restTemplate);
        if(bookingResult.getCode()==CommonConstants.SUCCESS){
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购成功!", CommonConstants.SUCCESS);
        }else{
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购失败!"+ JSON.toJSONString(bookingResult), CommonConstants.REQUEST_ERROR);
        }
    }

    @Override
    public Result<Object> updateOrderStateAboutLossLast(SwitchOrderPool pool) {
        //亏损单2直采（拆单后采购还是亏损）
        pool.setSysOrderState(62);
        pool.setIsOrder(1);
        pool.setRemark(DateUtil.getCurrTime() + " 当前为后台系统人工下单操作!");
        switchOrderPoolMapper.updateOrderState(pool);
        this.insertPoolStateHistroy(pool.getOrderId(),pool.getSysOrderState(),
                null,pool.getIsOrder(),pool.getRemark());

        //调用美团下单接口

        String orderId = pool.getOrderId();
        Example example = new Example(SwitchOrderPool.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("orderId",orderId);
        SwitchOrderPool switchOrderPool = switchOrderPoolMapper.selectOneByExample(example);
        Map switchOrderInfoMap = new HashMap();
        switchOrderInfoMap.put("orderId",orderId);
        SwitchOrderInfo switchOrderInfo = switchOrderInfoMapper.findOneByOrderId(switchOrderInfoMap);

        MtHotelOrderJobDealVo mtHotelOrderJobDealVo = new MtHotelOrderJobDealVo();
        mtHotelOrderJobDealVo.setSwPoolId(switchOrderPool.getId());
        mtHotelOrderJobDealVo.setSwOrderId(switchOrderPool.getOrderId());
        mtHotelOrderJobDealVo.setSwHotelId(switchOrderInfo.getHotelId());
        mtHotelOrderJobDealVo.setSwRoomId(switchOrderInfo.getRoomId());
        mtHotelOrderJobDealVo.setCheckinDate(DateUtil.switchDateParse(switchOrderInfo.getCheckinDate()));
        mtHotelOrderJobDealVo.setCheckoutDate(DateUtil.switchDateParse(switchOrderInfo.getCheckoutDate()));
        mtHotelOrderJobDealVo.setRoomnum(switchOrderInfo.getRoomnum());
        mtHotelOrderJobDealVo.setTotalPrice(switchOrderInfo.getOrderPrice().multiply(new BigDecimal(100)).intValue());
        mtHotelOrderJobDealVo.setPersonNames(switchOrderInfo.getCustomerName());
        mtHotelOrderJobDealVo.setContactName(switchOrderInfo.getContactName());
        mtHotelOrderJobDealVo.setContactPhone("4009700950");
        mtHotelOrderJobDealVo.setSysStatus(40);//40 人工采购
        //获取美团对应酒店id 商品id
        SwitchCreateRoomDto switchCreateRoomDto = switchCreateRoomService.getMtInfoBySwitchRoomId(Integer.valueOf(switchOrderInfo.getRoomId()));
        log.info("人工采购switchCreateRoomDto={}",switchCreateRoomDto);
        mtHotelOrderJobDealVo.setMtHotelId(String.valueOf(switchCreateRoomDto.getMtHotelId()));
        mtHotelOrderJobDealVo.setGoodsId(switchCreateRoomDto.getMtGoodId());
        String dataJson = JacksonUtil.objectToJson(mtHotelOrderJobDealVo);
        log.info("人工采购dataJson={}",dataJson);
        //调用美团下单接口
        SendUtils.dingMsgOrder("[HHB-RG-BOOKING] 很好办后台人工采购 ",DateUtil.getCurrTime()+" 订单号="+switchOrderPool.getOrderId(), MessageEnums.genre.ORDER_NOTICY.getCode(),switchOrderPool.getOrderId(),restTemplate);
        Result bookingResult = RestTemplateUtils.post(CommonUrlConstants.MEITUAN_HOST+"/mtHotelOrderDeal/jobNewOrderBooking",dataJson,restTemplate);
        if(bookingResult.getCode()==CommonConstants.SUCCESS){
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购成功!", CommonConstants.SUCCESS);
        }else{
            log.info("采购返回:"+ JSON.toJSONString(bookingResult));
            return new Result<>("采购失败!"+ JSON.toJSONString(bookingResult), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * <H1>人工拒单</H1>
     *  系统状态2  美团状态 0   下单状态 0 延时单    可操作人工拒单
     * @return hotel.base.oversea.utils.Result<java.lang.Object>
     * @author HuangT
     * @Date 2020/9/7 15:01
     */
    @Override
    public Result<Object> updateOrderStateAboutReject(String swOrderId) {
        //查询美团是否已下单成功则不可操作携程拒单
        Integer has = this.checkExistValiBookingBySwOrderId(swOrderId);
        if(has==0){
            SwitchOrderPool switchOrderPool = new SwitchOrderPool();
            switchOrderPool.setOrderId(swOrderId);

            OperateDltOrder operateDltOrder = new OperateDltOrder();
            operateDltOrder.setOrderId(swOrderId);
            operateDltOrder.setOperaterType(1);//拒绝
            log.info("人工拒单updateOrderStateAboutReject={}", JSON.toJSONString(operateDltOrder));
            Result result = switchOrderInfoService.operaterDltOrder(operateDltOrder);
            if(result.getCode() == CommonConstants.SUCCESS) {
                //修改pool表状态
                switchOrderPool.setSysOrderState(11);//已拒绝
                switchOrderPool.setIsOrder(1);
                switchOrderPool.setRemark(DateUtil.getCurrTime() + " 当前为后台系统人工拒单操作!result="+ JSON.toJSONString(result));
                switchOrderPoolMapper.updateOrderState(switchOrderPool);

                this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),
                        null,switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
                return new Result<>("拒单成功!", CommonConstants.SUCCESS);
            }else{
                switchOrderPool.setRemark(DateUtil.getCurrTime() + " 当前为后台系统人工拒单操作失败了!response="+ JSON.toJSONString(result));
                this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),
                        null,switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
                return new Result<>("当前拒单操作失败了，携程接口返回="+ JSON.toJSONString(result), CommonConstants.ERROR);
            }
        }
        return new Result<>("当前正在美团采购中或已预订成功不可拒单携程，请核实美团状态!", CommonConstants.ERROR);
    }
    @Override
    public Result<Object> rgPoolOrder(String swOrderId) {
        SwitchOrderPool switchOrderPool = new SwitchOrderPool();
        switchOrderPool.setOrderId(swOrderId);
        //修改pool表状态
        switchOrderPool.setSysOrderState(12);//人工处理
        switchOrderPool.setIsOrder(1);
        switchOrderPool.setRemark(DateUtil.getCurrTime() + " 后台系统锁单操作");
        switchOrderPoolMapper.updateOrderState(switchOrderPool);
        this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),switchOrderPool.getMtOrderState(),switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
        SendUtils.dingMsgOrder("[HHB-RG-LOCK] 很好办后台人工锁单，程序不再操作 ",DateUtil.getCurrTime()+" 订单号="+switchOrderPool.getOrderId(), MessageEnums.genre.DELAYED_ORDER.getCode(),swOrderId,restTemplate);
        this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),
                null,switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
        return new Result<>("锁单成功!", CommonConstants.SUCCESS);
    }

    @Override
    public Result<Object> unlockPoolOrder(String swOrderId) {
        SwitchOrderPool switchOrderPool = new SwitchOrderPool();
        switchOrderPool.setOrderId(swOrderId);
        //修改pool表状态
        switchOrderPool.setSysOrderState(2);//延时单
        switchOrderPool.setIsOrder(0);
        switchOrderPool.setRemark(DateUtil.getCurrTime() + " 后台系统解锁操作");
        switchOrderPoolMapper.updateOrderState(switchOrderPool);
        this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),switchOrderPool.getMtOrderState(),switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
        SendUtils.dingMsgOrder("[HHB-RG-LOCK] 很好办后台人工解锁恢复为延时单 ",DateUtil.getCurrTime()+" 订单号="+switchOrderPool.getOrderId(), MessageEnums.genre.DELAYED_ORDER.getCode(),swOrderId,restTemplate);
        this.insertPoolStateHistroy(switchOrderPool.getOrderId(),switchOrderPool.getSysOrderState(),
                null,switchOrderPool.getIsOrder(),switchOrderPool.getRemark());
        return new Result<>("解锁成功!", CommonConstants.SUCCESS);
    }


    @Override
    public Result<Object> updateMtOrderIdByOrderId(Map map) {
        int retUpd = switchOrderPoolMapper.updateMtOrderIdByOrderId(map);
        if(retUpd != -1){
            return new Result<>(CommonConstants.SUCCESS);
        }else{
            return new Result<>(CommonConstants.ERROR);
        }
    }
}
